package com.example.springbean;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.HeadersExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 15871
 */
@EnableAsync
@EnableAspectJAutoProxy(exposeProxy = true)
@EnableTransactionManagement
@SpringBootApplication
public class SpringBeanApplication {


    /**
     * Header Pattern.  交换机 Exchange
     **/
    @Bean
    public Queue headerQueue() {
        return new Queue("header.queue", true);
    }

    @Bean
    public HeadersExchange headersExchange() {
        return new HeadersExchange("header.exchange");
    }

    @Bean
    public Binding headerBinding() {
        Map<String, Object> map = new HashMap<>();
        map.put("header1", "value1");
        map.put("header2", "value2");
        return BindingBuilder.bind(headerQueue()).to(headersExchange()).whereAll(map).match();
        // whereXxx() 方法代表了匹配规则

    }


    public static void main(String[] args) {
       SpringApplication.run(SpringBeanApplication.class, args);
    }

}
